class Solution
{
public:
    int countWays(vector<int> &nums)
    {
        int n = nums.size();
        nums.insert(nums.begin(), -1);
        nums.push_back(INT_MAX);

        sort(nums.begin(), nums.end());
        int count = 0;
        for (int i = 0; i < nums.size(); i++)
        {
            if (nums[i] < i && nums[i + 1] > i)
            {
                count++;
            }
        }
        return count;
    }
};